
export default {
    setToken(state, token) {
        state.token = token
    },
    setUserInfo(state, userInfo) {
        state.userInfo = userInfo
    },
    setUserAmount(state, amount) {
        if (state.userInfo)
            state.userInfo.amount = amount
    },
    setInvNum(state, num) {
        state.invNum = num
    },
    setInvList(state, invList) {
        state.invList = invList
    },
    clearInvList(state) {
        state.invNum = null
        state.invList = []
    },
    appendInvListRow(state, invData) {
        for (let idx in state.invList) {
            if (invData.invCode !== "" && state.invList[idx].invCode === invData.invCode && state.invList[idx].invNum === invData.invNum) {
                invData.invTip = "重复记录"
                break
            }
        }
        state.invList.push(invData)
    },
    updateInvListRow(state, invData) {
        for (let idx in state.invList) {
            if (invData.invCode !== "" && state.invList[idx].invCode === invData.invCode && state.invList[idx].invNum === invData.invNum) {
                state.invList[idx] = { ...state.invList[idx], ...invData }
                return true
            }
        }
    },
    updateInvListVal(state, [invCode, invNum, key, val]) {
        for (let idx in state.invList) {
            if (state.invList[idx].invCode === invCode && state.invList[idx].invNum === invNum) {
                state.invList[idx][key] = val
                return true
            }
        }
        return false
    },
    clearInfo(state) {
        state.token = null
        state.userInfo = null
        state.invList = []
        localStorage.removeItem("token")
    }
}